<?php
require_once dirname(__FILE__)."/../init.php";

$recipient = $_POST['recipient'];
$message = $_POST['message'];

$send = $_POST['send'];
$draft = $_POST['draft'];

$sms = new SMS();
$sms->setMessage($message);
$sms->setRecipientName(RecipientUtils::extractRecipientName($recipient));
$recipientName = $sms->getRecipientName();
$sms->setRecipientMobileNumber(RecipientUtils::extractRecipientNumber($recipient));
$sms->setLastModifiedDate(date("Y-m-d H:i:s"));


$owner = ServiceFactory::getUserService()->getByUid($_uid);
$sms->setSenderId($owner->getId());

if ($send == null) {
    // send as draft and redirect to compose message
    $sms->setStatus(SMS::STATUS_DRAFT);
    ServiceFactory::getSMSService()->add($sms);
?>

<fb:redirect url="index.php?_page=drafts&operation=add&success=true" />

<?php
} else {
    // send now and save
    $sms->setStatus(SMS::STATUS_SENT);
    ServiceFactory::getSMSService()->add($sms);
?>

<fb:redirect url="index.php?_page=compose&operation=add&success=true" />

<?php
}
?>
